RTOS_SOURCE_DIR=../../FreeRTOS
CMSIS_SOURCE_DIR=../../CMSIS
PRJ_COMMON_DIR=../ProjectTasks
#DEMO_INCLUDE_DIR=D:/workspace/LPC1700/CommonDemoTasks/include
#UIP_COMMON_DIR=./uip
LCD_COMMON_DIR=./LCD
UART_COMMON_DIR=./uart
WEB_COMMON_DIR=./webserver

CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy
SIZE=arm-none-eabi-size
LDSCRIPT=magister.ld

LINKER_FLAGS=-mthumb -nostartfiles -Xlinker -omagister.elf -Xlinker -M -Xlinker -Map=magister.map

DEBUG=-g3
OPTIM=-O0

CFLAGS= $(DEBUG) \
      $(OPTIM) \
      -T$(LDSCRIPT) \
      -I . \
      -I $(RTOS_SOURCE_DIR)/include \
      -I $(RTOS_SOURCE_DIR)/portable/GCC/ARM_CM3 \
      -I $(CMSIS_SOURCE_DIR)/Core \
      -I $(CMSIS_SOURCE_DIR)/Device \
      -I $(PRJ_COMMON_DIR) \
      -I $(WEB_COMMON_DIR) \
      -I $(LCD_COMMON_DIR) \
      -I $(UART_COMMON_DIR) \
      -D GCC_ARMCM3 \
      -mcpu=cortex-m3 \
      -D PACK_STRUCT_END=__attribute\(\(packed\)\) \
      -D ALIGN_STRUCT_END=__attribute\(\(aligned\(4\)\)\) \
      -fomit-frame-pointer \
      -fno-dwarf2-cfi-asm \
      -fno-strict-aliasing
      
THUMB_SOURCE= \
      main.c \
      $(LCD_COMMON_DIR)/portlcd.c \
      $(LCD_COMMON_DIR)/lcd.c \
      $(UART_COMMON_DIR)/uart.c \
      $(RTOS_SOURCE_DIR)/list.c \
      $(RTOS_SOURCE_DIR)/queue.c \
      $(RTOS_SOURCE_DIR)/tasks.c \
      $(RTOS_SOURCE_DIR)/portable/GCC/ARM_CM3/port.c \
      $(RTOS_SOURCE_DIR)/portable/MemMang/heap_2.c \
      $(CMSIS_SOURCE_DIR)/Core/core_cm3.c \
      $(CMSIS_SOURCE_DIR)/Device/system_LPC17xx.c \
      $(WEB_COMMON_DIR)/emac.c \
      $(WEB_COMMON_DIR)/httpd.c \
      $(WEB_COMMON_DIR)/httpd-cgi.c \
      $(WEB_COMMON_DIR)/httpd-fs.c \
      $(WEB_COMMON_DIR)/http-strings.c \
      $(WEB_COMMON_DIR)/psock.c \
      $(WEB_COMMON_DIR)/timer.c \
      $(WEB_COMMON_DIR)/uip.c \
      $(WEB_COMMON_DIR)/uip_arp.c \
      $(WEB_COMMON_DIR)/uIP_Task.c \
      syscalls.c \
      cr_startup_lpc17.c

THUMB_OBJS = $(THUMB_SOURCE:.c=.o)

all: magister.bin

magister.bin : magister.hex
	$(OBJCOPY) magister.elf -O binary magister.bin
   
magister.hex : magister.elf
	$(OBJCOPY) magister.elf -O ihex magister.hex

magister.elf : $(THUMB_OBJS) $(ARM_OBJS) makefile
	$(CC) $(CFLAGS) $(ARM_OBJS) $(THUMB_OBJS) $(LIBS) $(LINKER_FLAGS)

$(THUMB_OBJS) : %.o : %.c makefile FreeRTOSConfig.h
	$(CC) -c $(CFLAGS) -mthumb $< -o $@

$(ARM_OBJS) : %.o : %.c makefile FreeRTOSConfig.h
	$(CC) -c $(CFLAGS) $< -o $@

clean:
	rm $(THUMB_OBJS)
	touch makefile
	rm magister.elf
	rm magister.hex
	rm magister.bin
	rm magister.map